package com.keepers.repair.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.VideoView;

import com.keepers.repair.R;
import com.keepers.repair.helper.ConsValue;
import com.keepers.repair.net.LogUtil;
import com.keepers.repair.utils.AlertToast;
import com.keepers.repair.view.TitleBar;

/**
 * auth aboom
 * date 2018/11/26
 */
public class MovieSuccessActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_movie_success);
        String filePath = getIntent().getStringExtra(ConsValue.INTENT_KEY);
        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
        LogUtil.e("filePath:" + filePath + " fileName:" + fileName);
        TitleBar titleBar = f(R.id.title_bar);
        titleBar.initializeHeader("视频回放");
        titleBar.setRightText("确定", v -> {
            Intent intent = new Intent();
            intent.putExtra(ConsValue.INTENT_KEY, filePath);
            setResult(Activity.RESULT_OK, intent);
            finish();
        });
        VideoView videoView = f(R.id.video_view);
        videoView.setVideoPath(filePath);
        f(R.id.button1).setOnClickListener(v -> videoView.start());
        f(R.id.button2).setOnClickListener(v -> videoView.pause());
        f(R.id.button3).setOnClickListener(v -> {
            videoView.resume();
            videoView.start();
        });
        f(R.id.button4).setOnClickListener(v -> AlertToast.show("视频长度：" + (videoView.getDuration() / 1000) + "秒"));
    }
}


